<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>日志查看 | Taras 编辑工具</title>
  <script type="text/javascript" src="/lib/js/jquery.js"></script>
  <script type="text/javascript" src="/lib/js/sprintf.js"></script>
  <script type="text/javascript" src="/lib/js/jquery.scrollTo.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
        $("#show-older").click(function() {
            $("div.old").show();
            $.scrollTo($(this), 1000);
        });
    });
  </script>
  <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css">
  <style>
    div {
        margin: 0px 50px;
    }
    div.old {
        display: none;
        background-color: #cdcdcd;
    }
    div.recent {

    }
  </style>
</head>
<?php

function sort_by_mtime($a, $b) {
    $t1 = filemtime($a);
    $t2 = filemtime($b);
    return $t2 - $t1;
}

ob_implicit_flush();

$log_path = '/home/luanjunyi/run/taras-sharded/';
$email = trim($_GET['email']);

echo "email: $email<br /><br />";

$cur_log_files = glob("{$log_path}/*/taras.debug");
$old_log_files = glob("{$log_path}/*/taras.debug.*");

usort($cur_log_files, "sort_by_mtime");
usort($old_log_files, "sort_by_mtime");


// process most recent log
echo "most recent:<br /><br />";
echo "<div class='log-detail recent'>";
foreach ($cur_log_files as $log_file) {
  include('inspect-id-in-log.php');
}
echo "</div>";

// process older log
echo "<button id='show-older'>show older log:</button><br /><br />";

foreach ($old_log_files as $log_file) {
  echo "<div class='log-detail old'>";
  include('inspect-id-in-log.php');
  echo "</div>";
}
?>
</html>